package com.qx.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.Data;

@Entity
@Data
@Table(name = "roles")
public class Roles {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	private String name;
	private Integer int0;
	private String string0;

	@JsonIgnore
	// 指定多对多关系，默认懒加载，只有调用getter方法时才加载数据
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "userroles", // 指定第三张中间表名称
			joinColumns = { @JoinColumn(name = "roleid") }, // 本表主键
			inverseJoinColumns = { @JoinColumn(name = "userid") }) // 多对多关系另一张表
	// NotFound:意思是找不到引用的外键数据时忽略，NotFound默认是exception
	@NotFound(action = NotFoundAction.IGNORE)
	private List<Users> ulist = new ArrayList<Users>();

	@JsonIgnore
	// 指定多对多关系，默认懒加载，只有调用getter方法时才加载数据
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "rolemodules", // 指定第三张中间表名称
			joinColumns = { @JoinColumn(name = "roleid") }, // 本表主键
			inverseJoinColumns = { @JoinColumn(name = "moduleid") }) // 多对多关系另一张表
	// NotFound:意思是找不到引用的外键数据时忽略，NotFound默认是exception
	@NotFound(action = NotFoundAction.IGNORE)
	private List<Modules> mlist = new ArrayList<Modules>();

	@JsonIgnore
	// 指定多对多关系，默认懒加载，只有调用getter方法时才加载数据
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "rolepermission", // 指定第三张中间表名称
			joinColumns = { @JoinColumn(name = "roleid") }, // 本表主键
			inverseJoinColumns = { @JoinColumn(name = "permissionid") }) // 多对多关系另一张表
	// NotFound:意思是找不到引用的外键数据时忽略，NotFound默认是exception
	@NotFound(action = NotFoundAction.IGNORE)
	private List<Permission> list = new ArrayList<Permission>();

	public String test1() {
		return "Roles [id=" + id + ", name=" + name + ", int0=" + int0 + ", string0=" + string0 + ", ulist=" + ulist
				+ "]";
	}

	public String test2() {
		return "Roles [id=" + id + ", name=" + name + ", int0=" + int0 + ", string0=" + string0 + ", list=" + list
				+ "]";
	}

	public String test3() {
		return "Roles [id=" + id + ", name=" + name + ", int0=" + int0 + ", string0=" + string0 + ", mlist=" + mlist
				+ "]";
	}

}
